/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jboss.seam.example.booking.action;

/**
 *
 * @author RHO
 */
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.bpm.Actor;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage.Severity;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.jbpm.JbpmContext;

@Name("taskListPage")
@Scope(ScopeType.CONVERSATION)
@Restrict("#{identity.loggedIn}")
public class TaskListPage {

    @In
    private Actor actor;
    
    @Out(value = "myTasksQuery", required = false)
    List<TaskInstance> groupTaskListFound = new ArrayList<TaskInstance>();

    @In
    private JbpmContext jbpmContext;
    
    @Begin(join = true)
    @End
    public String changePassword(TaskInstance task) {
        String oldPasswd = (String) task.getVariable("oldPasswd");
        String newPasswd = (String) task.getVariable("newPasswd");
        String newPasswdRepeat = (String) task.getVariable("newPasswdRepeat");
        
        System.out.println("oldPasswd:" + oldPasswd);
        System.out.println("newPasswd:" + newPasswd);
        System.out.println("newPasswdRepeat:" + newPasswdRepeat);

        task.start(actor.getId());
        task.end("done");

        List<String> actorIds = new ArrayList<String>();

        actorIds.add("admin");

        groupTaskListFound = jbpmContext.getGroupTaskList(actorIds);
        if (groupTaskListFound.size() > 0) {
            for (TaskInstance taskInstance : groupTaskListFound) {
                TaskInstance firstTaskInstance = taskInstance;
                ProcessInstance processInstance = firstTaskInstance.getProcessInstance();
                jbpmContext.save(processInstance);
            }
        }

        FacesMessages.instance().addFromResourceBundle(Severity.INFO, "Activation Email Sent");

        return "show_task_list";
    }
}
